/***************************************************************************
 创建者：华磊
 开始时间：         : 2020.11.16
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 2017.05.04 华磊 视觉页面

 ***************************************************************************
 *   程序指令主视窗
 *                                                                         *
 ***************************************************************************/
#include "programview.h"
#include "ui_programview.h"
#include <QScrollBar>
#include <QLabel>
#include "../CommunicateDelegate/communicatenormaldelegate.h"
#include "weldpropertydialog.h"
#include "weldconditiondialog.h"
#include "domparser.h"
#include "buttonfunctionmap.h"
#include <QMessageBox>
#include "weavemotionconditiondialog.h"
extern CommunicateNormalDelegate *communicateNormalThread;


ProgramView::ProgramView(int styleId, CommunicateNormalDelegate *communicateNormalDelegateIn,
                         GlobalData *globalDataIn, MoveOperation *moveOperationIn,
                         GlobalData *ioDataIn, MapView *mapViewIn, QWidget *parent):
        QDialog(parent),
        ui(new Ui::ProgramView)
{
    ioData=ioDataIn;

    ui->setupUi(this);
    initialDisplayStyle(styleId);//修改页面显示风格
    QMap<int, int> usualButtonFunctionOut;
    readButtonConfigFunction(D_USUAL_BUTTON_FUNCTION_PATH,usualButtonFunctionOut);

    initFlag = true;

    progromListView = new ProgromListView(styleId);
    progromListView->programView = this;

    buttonFunMap=new ButtonFunctionMap(usualButtonFunctionOut);
    motionInstructionView = new MotionInstructionView(styleId,ioData);
    motionInstructionDelegate = new MotionInstructionDelegate(globalDataIn,moveOperationIn,ioDataIn);
    motionInstructionDelegate->motionInstructionView = motionInstructionView; 
    motionInstructionView->programView = this;
    motionInstructionView->motionInstruction2View->programView = this;    

    ifInstructionView = new IfInstructionView(styleId);
    ifInstructionDelegate = new IfInstructionDelegate(globalDataIn,communicateNormalDelegateIn,progromListView);
    ifInstructionDelegate->ifInstructionView = ifInstructionView;
    ifInstructionView->programView = this;

    labelJmpView = new LabelJmpView(styleId);

    labelJmpDelegate = new LabelJmpDelegate(globalDataIn,communicateNormalDelegateIn,labelJmpView,progromListView);
    labelJmpView->programView = this;


    waitInstructionView = new WaitInstructionView(styleId);
    waitInstructionDelegate = new WaitInstructionDelegate;
    waitInstructionDelegate->waitInstructionView = waitInstructionView;
    waitInstructionView->programView = this;

    forInstructionView = new ForInstructionView(styleId);
    forInstructionDelegate = new ForInstructionDelegate;
    forInstructionDelegate->forInstructionView = forInstructionView;
    forInstructionView->programView = this;

    registerInstructionView = new RegisterInstructionView(styleId);
    registerInstructionDelegate = new RegisterInstructionDelegate;
    registerInstructionDelegate->registerInstructionView = registerInstructionView;
    registerInstructionView->programView = this;

    selectInstructionView = new SelectInstructionView(styleId);
    selectInstructionDelegate = new SelectInstructionDelegate;
    selectInstructionDelegate->selectInstructionView = selectInstructionView;
    selectInstructionView->programView = this;

    skipConditionView = new SkipConditionView;
    skipConditionDelegate = new SkipConditionDelegate;
    skipConditionDelegate->skipConditionView = skipConditionView;
    skipConditionView->programView = this;

    outputInstructionView = new OutputInstructionView(styleId);
    outputInstructionDelegate = new OutputInstructionDelegate;
    outputInstructionDelegate->outputInstructionView = outputInstructionView;
    outputInstructionView->programView = this;

    coordinateInstructionView = new CoordinateInstructionView(styleId);
    coordinateInstructionDelegate = new CoordinateInstructionDelegate;
    coordinateInstructionDelegate->coordinateInstructionView = coordinateInstructionView;
    coordinateInstructionView->programView = this;

    otherInstructionView = new OtherInstructionView(styleId);
    otherInstructionDelegate = new OtherInstructionDelegate;
    otherInstructionDelegate->otherInstructionView = otherInstructionView;
    otherInstructionView->programView = this;
    otherInstructionView->otherInstruction2View->programView = this;

    palletInstructionView = new PalletInstructionView(styleId);
    palletInstructionDelegate = new PalletInstructionDelegate(globalDataIn,moveOperationIn);
    palletInstructionDelegate->palletInstructionView = palletInstructionView;
    palletInstructionView->programView = this;
    palletInstructionView->palletMotionInstructionView->programView = this;

    visionInstructionView = new VisionInstructionView(styleId);
    visionInstructionDelegate = new VisionInstructionDelegate;
    //visionInstructionDelegate->visionInstructionView = visionInstructionView;
    visionInstructionView->programView = this;

    pointViewDialog = new PointViewDialog;      //点查看
    programSaveDialog = new ProgramSaveDialog;  //保存提示

    moveMagInstructionView = new MoveMagInstructionView(styleId);
    moveMagInstructionDelegate = new MoveMagInstructionDelegate;
    moveMagInstructionView->programView = this;
    moveMagInstructionDelegate->moveMagInstructionView = moveMagInstructionView;

    //  MOVE_FREE
    moveFreeInstructionDelegate = new MoveFreeInstructionDelegate(mapViewIn,globalDataIn,communicateNormalDelegateIn);
    moveFreeInstructionView = new MoveFreeInstructionView(styleId,communicateNormalDelegateIn);
    moveFreeInstructionView->programView = this;
    moveFreeInstructionDelegate->moveFreeInstructionView = moveFreeInstructionView;
    moveFreeInstructionView->moveFreeDPointView->programView = this;
    moveFreeInstructionView->moveFreeInstructionTrackView->programView = this;
    moveFreeInstructionView->moveFreeMoveTypeView->programView = this;
    moveFreeInstructionView->moveFreeVmarkSettingView->programView = this;


    // MODBUS_START
    modbusStartInstructionView = new ModbusStartInstructionView(styleId);
    modbusStartInstructionDelegate = new ModbusStartInstructionDelegate;
    modbusStartInstructionView->programView = this;
    modbusStartInstructionDelegate->modbusStartInstructionView = modbusStartInstructionView;

    // MODBUS_READ
    modbusReadInstructionView = new ModbusReadInstructionView(styleId);
    modbusReadInstructionDelegate = new ModbusReadInstructionDelegate;
    modbusReadInstructionView->programView = this;
    modbusReadInstructionDelegate->modbusReadInstructionView = modbusReadInstructionView;

    // MODBUS_WRITE
    modbusWriteInstructionView = new ModbusWriteInstructionView(styleId);
    modbusWriteInstructionDelegate = new ModbusWriteInstructionDelegate;
    modbusWriteInstructionView->programView = this;
    modbusWriteInstructionDelegate->modbusWriteInstructionView = modbusWriteInstructionView;

    // SET_ODOM
    odometryInstructionView = new OdometryInstructionView(styleId);
    odometryInstructionDelegate = new OdometryInstructionDelegate;
    odometryInstructionDelegate->odometryInstructionView = odometryInstructionView;
    odometryInstructionView->programView = this;

    // TCP_START
    tcpStartInstructionView = new TCPStartInstructionView(styleId);
    tcpStartInstructionDelegate = new TCPStartInstructionDelegate;
    tcpStartInstructionDelegate->tcpStartInstructionView = tcpStartInstructionView;
    tcpStartInstructionView->programView = this;

    // TCP_READ
    tcpReadInstructionView = new TCPReadInstructionView(styleId);
    tcpReadInstructionDelegate = new TCPReadInstructionDelegate;
    tcpReadInstructionDelegate->tcpReadInstructionView = tcpReadInstructionView;
    tcpReadInstructionView->programView = this;

    // TCP_WRITE
    tcpWriteInstructionView = new TCPWriteInstructionView(styleId);
    tcpWriteInstructionDelegate = new TCPWriteInstructionDelegate;
    tcpWriteInstructionDelegate->tcpWriteInstructionView = tcpWriteInstructionView;
    tcpWriteInstructionView->programView = this;

    // MUSIC
    musicInstructionView = new MusicInstructionView(styleId);
    musicInstructionDelegate = new MusicInstructionDelegate(globalDataIn);
    musicInstructionDelegate->musicInstructionView = musicInstructionView;
    musicInstructionView->programView = this;

    // CHARGING
    chargingInstructionView = new ChargingInstructionView(styleId);
    chargingInstructionDelegate = new ChargingInstructionDelegate;
    chargingInstructionDelegate->chargingInstructionView = chargingInstructionView;
    chargingInstructionView->programView = this;

    // LIFT
    liftMechanismInstructionView = new LiftMechanismInstructionView(styleId);
    liftMechanismInstructionDelegate = new LiftMechanismInstructionDelegate;
    liftMechanismInstructionDelegate->liftMechanismInstructionView = liftMechanismInstructionView;
    liftMechanismInstructionView->programView = this;

    // LOAD_MAP
    loadMapInstructionView = new LoadMapInstructionView(styleId);
    loadMapInstructionDelegate = new LoadMapInstructionDelegate(globalDataIn);
    loadMapInstructionDelegate->loadMapInstructionView = loadMapInstructionView;
    loadMapInstructionView->programView = this;

    // ROBOT_MOVE
    robotMoveInstructionView = new RobotMoveInstructionView(styleId);
    robotMoveInstructionDelegate = new RobotMoveInstructionDelegate;
    robotMoveInstructionDelegate->robotMoveInstructionView = robotMoveInstructionView;
    robotMoveInstructionView->programView = this;

    checkBatteryView = new CheckBatteryView(styleId);
    checkBatteryDelegate = new CheckBatteryDelegate();
    waitCommandView = new WaitCommandView(styleId);
    waitCommandDelegate = new WaitCommandDelegate();

    checkBatteryDelegate->checkBatteryView = checkBatteryView;
    checkBatteryView->programView = this;
    waitCommandDelegate->waitCommandView = waitCommandView;
    waitCommandView->programView = this;

    rollerInstructionView = new RollerInstructionView(styleId);
    rollerInstructionDelegate = new RollerInstructionDelegate;
    rollerInstructionDelegate->rollerInstructionView = rollerInstructionView;
    rollerInstructionView->programView = this;

    axisMoveInstructionView=new AxisMoveInstructionView(styleId,this);
    axisMoveInstructionDelegate=new AxisMoveInstructionDelegate;
    axisMoveInstructionDelegate->instructionView = axisMoveInstructionView;

    weldStartInsView=new WeldStartInstructionView(styleId,this);
    weldEndInsView=new WeldEndInstructionView(styleId,this);//新指令20191130 ZHUHT
    weaveInsView=new WeaveInstructionView(styleId,this);
    weaveEndInsView=new WeaveEndInstructionView(styleId,this);
    trackWeldTASTInsView =new TrackWeldTASTInstructionView(styleId,this);
    trackWeldEndInsView =new TrackWeldEndInstructionView(this);
    watchDIInsView =new WatchDIInstructionView(styleId,this);
    lasercameraControlInsView=new LaserCameraControlInsView(styleId,this);
    lasercameraTrackInsView=new LaserCameraTrackInsView(styleId,this);
    lasercameraFetchPointInsView=new LaserCameraFetchPointInsView(styleId,this);
    bufferMoveView=new BufferMoveView(styleId,this);

    //焊接属性配置页面
    weldPropertyDialog = new WeldPropertyDialog(styleId,communicateNormalThread);
    weldPropertyDialog->setParent(this);
    weldPropertyDialog->hide();
    //焊接条件配置页面
    weldConditionDialog = new WeldConditionDialog(styleId,communicateNormalThread);
    weldConditionDialog->setParent(this);
    weldConditionDialog->hide();

    weaveConditionDialog = new WeaveMotionConditionDialog(styleId,communicateNormalThread);
    weaveConditionDialog->setParent(this);
    weaveConditionDialog->hide();

    motionInstructionView->setParent(this);
    motionInstructionView->motionInstruction2View->setParent(this);
    ifInstructionView->setParent(this);
    labelJmpView->setParent(this);
    progromListView->setParent(this);
    waitInstructionView->setParent(this);
    forInstructionView->setParent(this);
    registerInstructionView->setParent(this);
    selectInstructionView->setParent(this);
    skipConditionView->setParent(this);
    outputInstructionView->setParent(this);
    coordinateInstructionView->setParent(this);
    otherInstructionView->setParent(this);
    otherInstructionView->otherInstruction2View->setParent(this);
    palletInstructionView->setParent(this);
    palletInstructionView->palletMotionInstructionView->setParent(this);
    visionInstructionView->setParent(this);
    pointViewDialog->setParent(this);   //点查看

    moveMagInstructionView->setParent(this);
    moveFreeInstructionView->setParent(this);
    moveFreeInstructionView->moveFreeDPointView->setParent(this);
    moveFreeInstructionView->moveFreeInstructionTrackView->setParent(this);
    moveFreeInstructionView->moveFreeMoveTypeView->setParent(this);
    moveFreeInstructionView->moveFreeVmarkSettingView->setParent(this);

    odometryInstructionView->setParent(this);

    tcpStartInstructionView->setParent(this);
    tcpReadInstructionView->setParent(this);
    tcpWriteInstructionView->setParent(this);

    musicInstructionView->setParent(this);
    liftMechanismInstructionView->setParent(this);

    modbusStartInstructionView->setParent(this);
    modbusReadInstructionView->setParent(this);
    modbusWriteInstructionView->setParent(this);

    chargingInstructionView->setParent(this);
    loadMapInstructionView->setParent(this);

    //检测电池电量
    checkBatteryView->setParent(this);
    //等待命令
    waitCommandView->setParent(this);
    // 机械手控制指令
    robotMoveInstructionView->setParent(this);
    // 滚筒指令
    rollerInstructionView->setParent(this);


    motionInstructionView->setGeometry(5, 50, 451, 544);
    motionInstructionView->motionInstruction2View->setGeometry(5, 50, 451, 544);
    ifInstructionView->setGeometry(5, 50, 451, 544);
    labelJmpView->setGeometry(5, 50, 451, 544);
    progromListView->setGeometry(5, 50, 451, 544);
    waitInstructionView->setGeometry(5, 50, 451, 544);
    forInstructionView->setGeometry(5, 50, 451, 544);
    registerInstructionView->setGeometry(5, 50, 451, 544);
    selectInstructionView->setGeometry(5, 50, 451, 544);
    skipConditionView->setGeometry(5, 50, 451, 544);
    outputInstructionView->setGeometry(5, 50, 451, 544);
    coordinateInstructionView->setGeometry(5, 50, 451, 544);
    otherInstructionView->setGeometry(5, 50, 451, 544);
    otherInstructionView->otherInstruction2View->setGeometry(5, 50, 451, 544);
    palletInstructionView->setGeometry(5, 50, 451, 544);
    palletInstructionView->palletMotionInstructionView->setGeometry(5, 50, 451, 544);
    visionInstructionView->setGeometry(5, 50, 451, 544);
    pointViewDialog->setGeometry(5, 50, 451, 544);

    moveMagInstructionView->setGeometry(5, 50, 451, 544);
    moveFreeInstructionView->setGeometry(5,50,451,544);
    moveFreeInstructionView->moveFreeDPointView->setGeometry(5,50,451,544);
    moveFreeInstructionView->moveFreeInstructionTrackView->setGeometry(100,100,288,376);
    moveFreeInstructionView->moveFreeMoveTypeView->setGeometry(5,50,451,544);
    moveFreeInstructionView->moveFreeVmarkSettingView->setGeometry(5,50,451,544);

    modbusStartInstructionView->setGeometry(5, 50, 451, 544);
    modbusReadInstructionView->setGeometry(5, 50, 451, 544);
    modbusWriteInstructionView->setGeometry(5, 50, 451, 544);

    odometryInstructionView->setGeometry(5, 50, 451, 544);

    tcpStartInstructionView->setGeometry(5, 50, 451, 544);
    tcpReadInstructionView->setGeometry(5,50,451,544);
    tcpWriteInstructionView->setGeometry(5, 50, 451, 544);

    musicInstructionView->setGeometry(5, 50, 451, 544);

    chargingInstructionView->setGeometry(5, 50, 451, 544);
    liftMechanismInstructionView->setGeometry(5,50,451,544);
    loadMapInstructionView->setGeometry(5,50,451,544);

    //CHECK BATTERY
    checkBatteryView->setGeometry(5,50,451,544);
    //等待命令
    waitCommandView->setGeometry(5,50,451,544);
    // 机械手控制指令
    robotMoveInstructionView->setGeometry(5,50,451,544);
    // 滚筒指令
    rollerInstructionView->setGeometry(5,50,451,544);

    motionInstructionView->hide();
    motionInstructionView->motionInstruction2View->hide();
    ifInstructionView->hide();
    labelJmpView->hide();
    progromListView->hide();
    waitInstructionView->hide();
    forInstructionView->hide();
    registerInstructionView->hide();
    selectInstructionView->hide();
    skipConditionView->hide();
    outputInstructionView->hide();
    coordinateInstructionView->hide();
    otherInstructionView->hide();
    otherInstructionView->otherInstruction2View->hide();
    palletInstructionView->hide();
    palletInstructionView->palletMotionInstructionView->hide();
    visionInstructionView->hide();
    pointViewDialog->hide();
    programSaveDialog->hide();
    moveMagInstructionView->hide();
    moveFreeInstructionView->hide();
    moveFreeInstructionView->moveFreeDPointView->hide();
    moveFreeInstructionView->moveFreeInstructionTrackView->hide();
    moveFreeInstructionView->moveFreeMoveTypeView->hide();
    moveFreeInstructionView->moveFreeVmarkSettingView->hide();

    modbusStartInstructionView->hide();
    modbusReadInstructionView->hide();
    modbusWriteInstructionView->hide();

    odometryInstructionView->hide();

    tcpStartInstructionView->hide();
    tcpReadInstructionView->hide();
    tcpWriteInstructionView->hide();

    musicInstructionView->hide();
    chargingInstructionView->hide();

    liftMechanismInstructionView->hide();
    loadMapInstructionView->hide();

    checkBatteryView->hide();
    waitCommandView->hide();
    robotMoveInstructionView->hide();
    rollerInstructionView->hide();
    setGeometry(70,128,460,595);

    //对各个窗口指针进行初始化
    instructionMenu_usualyUsed1 = new InstructionMenu(buttonFunMap,this);
    instructionMenu_usualyUsed2 = new InstructionMenuSecond(buttonFunMap,this);
    instructionMenu_all = new InstructionAll;
    moveMenu = new MoveMenu;
    palletMenu = new PalletMenu;
    flowMenu = new FlowMenu();
    registerMenu = new RegisterMenu;
    ioMenu = new IoMenu;
    otherMenu1 = new OtherMenu;
    stampMenu = new StampMenu;
    otherMenu2 = new OtherNextPageMenu;
    weldMenu =new WeldMenu;

    guidanceMenu = new GuidanceMenu;
    modbusMenu = new ModbusMenu;
    tcpCommunicationMenu = new TCPCommunicationMenu;
    laserCameraMenu=new LaserCameraMenu;

    //为界面按钮填充文字
    ui->InstructionListBtn->setText(tr("指令列表"));
    ui->InstructionPropertyBtn->setText(tr("指令属性"));
    ui->MoveUpBtn->setText(tr("上移"));
    ui->MoveDownBtn->setText(tr("下移"));
    ui->DelBtn->setText(tr("删除"));
    ui->NoteBtn->setText(tr("注释"));
    ui->RecordPointBtn->setText(tr("载入点"));
    ui->ShowPointBtn->setText(tr("点查看"));
    ui->JToPointBtn->setText(tr("关节到点"));
    ui->LToPointBtn->setText(tr("直线到点"));
    ui->SaveBtn->setText(tr("保存"));

    ui->Command_tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);//不可编辑
    ui->Command_tableWidget->setColumnCount(1);

    ui->Command_tableWidget->horizontalHeader()->setStretchLastSection(true);

}

ProgramView::~ProgramView()
{
    delete ui;
}

void ProgramView::updateView(bool updateList, bool updateModel)
{
    //是否需要初始化 右侧menu
    if(initFlag)
    {
        ui->menu_stackedWidget->addWidget(instructionMenu_usualyUsed1);
        ui->menu_stackedWidget->addWidget(instructionMenu_all);
        ui->menu_stackedWidget->addWidget(moveMenu);
        ui->menu_stackedWidget->addWidget(palletMenu);
        ui->menu_stackedWidget->addWidget(flowMenu);
        ui->menu_stackedWidget->addWidget(registerMenu);
        ui->menu_stackedWidget->addWidget(ioMenu);
        ui->menu_stackedWidget->addWidget(otherMenu1);
        ui->menu_stackedWidget->addWidget(stampMenu);//NUM.9  2017.05.05
        ui->menu_stackedWidget->addWidget(guidanceMenu);
        ui->menu_stackedWidget->addWidget(modbusMenu);
        ui->menu_stackedWidget->addWidget(tcpCommunicationMenu);
        ui->menu_stackedWidget->addWidget(otherMenu2);
        ui->menu_stackedWidget->addWidget(instructionMenu_usualyUsed2);
        ui->menu_stackedWidget->addWidget(weldMenu);//NUM.15  2019.12.30
        ui->menu_stackedWidget->addWidget(laserCameraMenu);



        initFlag = false;
    }



    //是否需要更新指令内容
    if(updateList)
    {

        //设置指令内容    暂时不翻译
        ui->Command_tableWidget->setRowCount(fileInformation.size());

        if(ENUM_LAN_ENGLISH == editLanguage)         //英文翻译
        {
            for(int i = 0; i < fileInformation.size(); i++)
            {
                ui->Command_tableWidget->setItem(i, 0, new QTableWidgetItem(fileInformation[i]));
            }
        }
        else if(ENUM_LAN_CHINESE == editLanguage)    //中文翻译
        {
            emit showFileInfoChineseSignal();//翻译

            for(int i = 0; i < fileInformation.size(); i ++)
            {
                ui->Command_tableWidget->setItem(i, 0, new QTableWidgetItem(fileInformationChinese[i]));
            }


        }

    }

    //需要更新其他东西
    if(updateModel)
    {
        ui->Command_tableWidget->selectRow(currentLineIndex);

        ui->Root_Mode_Btn->setText(menuBtnTitle);

        //指令显示与否设置
        if(0 == menuViewShowFlag)
        {
            ui->HideOrShow_AddCommand_Btn->setStyleSheet(( QString("border-image: url(%1);").arg(hideOrShowBtnPicture)));

            ui->Root_Mode_Btn->hide();
            ui->menu_stackedWidget->hide();

            ui->Command_tableWidget->setFixedWidth(445);
            ui->Command_tableWidget->setColumnWidth(0, 400);
            ui->Command_tableWidget->resizeRowsToContents();  //行高根据内容自适应
        }
        else if(1 == menuViewShowFlag)
        {
            ui->HideOrShow_AddCommand_Btn->setStyleSheet(( QString("border-image: url(%1);").arg(hideOrShowBtnPicture)));

            ui->Root_Mode_Btn->show();
            ui->menu_stackedWidget->show();
            ui->menu_stackedWidget->setCurrentIndex(currentMenuIndex);

            ui->Command_tableWidget->setFixedWidth(225);
            ui->Command_tableWidget->setColumnWidth(0, 175);
            ui->Command_tableWidget->resizeRowsToContents();
        }
    }
}

void ProgramView::initialButtonText()
{
    instructionMenu_usualyUsed1->initialButtonText();
    instructionMenu_usualyUsed2->initialButtonText();
}


int ProgramView::getCurrentLineIndex()
{
    return (ui->Command_tableWidget->currentRow());
}

void ProgramView::on_MoveUpBtn_clicked()
{
    QMessageBox message(QMessageBox::Question, "note", "即将执行指令上移操作!"
                        , QMessageBox::Ok , this);

    message.exec();
    emit moveUpInstruction(getCurrentLineIndex());
}

void ProgramView::on_MoveDownBtn_clicked()
{
    QMessageBox message(QMessageBox::Question, "note", "即将执行指令下移操作!"
                        , QMessageBox::Ok , this);

    message.exec();
    emit moveDownInstruction(getCurrentLineIndex());
}

void ProgramView::on_DelBtn_clicked()
{
    QMessageBox message(QMessageBox::Question, "note", "是否执行指令删除操作!"
                        , QMessageBox::Yes | QMessageBox::No, this);
    if(message.exec() == QMessageBox::No)
    {
        return ;
    }
    emit deleteInstruction(getCurrentLineIndex());
}

void ProgramView::on_NoteBtn_clicked()
{
    QMessageBox message(QMessageBox::Question, "note", "即将执行指令注释操作!"
                        , QMessageBox::Ok , this);

    message.exec();
    emit noteInstruction(getCurrentLineIndex());
}

void ProgramView::on_RecordPointBtn_clicked()
{
    //更新程序控件的选择行号。
    getCurrentSelectionInstruction();

    if((currentSeletionInstruction.contains("MOVE_FREE")))
    {
        // 自由导航指令点载入信号
        emit recordDPointSignal(E_RECORD_PROGRAM_VIEW_POINT);
    }
    else if((currentSeletionInstruction.startsWith("J P["))  || \
      ((currentSeletionInstruction.startsWith("C P["))) || \
      ((currentSeletionInstruction.startsWith("   P[")))  || \
       (currentSeletionInstruction.startsWith("L P[")))
    {
        // 关节指令点载入信号
        emit recordPoint(getCurrentLineIndex());
    }
    else
    {

    }


    // 一次选中后清除,避免选中指令载入完成后,没有
    currentSeletionInstruction.clear();
}

void ProgramView::on_ShowPointBtn_clicked()
{
    if(!fileInformation.isEmpty())
    {
        emit showPoint(fileInformation[getCurrentLineIndex()]);
    }
}

void ProgramView::on_JToPointBtn_pressed()
{
    emit jToPoint(getCurrentLineIndex());
}

void ProgramView::on_JToPointBtn_released()
{
    emit stopPointMove();
}

void ProgramView::on_LToPointBtn_pressed()
{
    emit lToPoint(getCurrentLineIndex());
}

void ProgramView::on_LToPointBtn_released()
{
    emit stopPointMove();
}

void ProgramView::on_SaveBtn_clicked()
{
    //emit saveFile(fileName, fileInformation);
    emit saveFileSignal();
}

void ProgramView::on_InstructionListBtn_clicked()
{
    instructionListFlag = 0;
    // 更新保存当前指令数据
    emit saveCurrentInstruction_Signal();
    editInstructionViewShowOrHide();
}

void ProgramView::on_InstructionPropertyBtn_clicked()
{
    if(pointViewDialog->isHidden())//点查看是关闭的才能点击有效,查看指令属性
    {
        if(getCurrentLineIndex() >= 0)
        {
            emit getCurrentLineInstruction(getCurrentLineIndex());          
            emit openInstructionEditView();
        }
    }
}

void ProgramView::on_HideOrShow_AddCommand_Btn_clicked()
{

    emit menuViewShowOrHide(menuViewShowFlag);
}

void ProgramView::on_Root_Mode_Btn_clicked()
{
    //currentMenuIndex = ui->menu_stackedWidget->currentIndex();

    //emit menuChange(currentMenuIndex);
    emit menuChange();
}

void ProgramView::editInstructionViewShowOrHide()
{
    if(0 == instructionListFlag)
    {
        ui->InstructionListBtn->setStyleSheet(editInstructionBtnPicture2);
        ui->InstructionPropertyBtn->setStyleSheet(editInstructionBtnPicture1);

        ui->wdcommandmain->show();
        ui->HideOrShow_AddCommand_Btn->show();

        motionInstructionView->hide();
        motionInstructionView->motionInstruction2View->hide();
        ifInstructionView->hide();
        labelJmpView->hide();
        waitInstructionView->hide();
        forInstructionView->hide();
        registerInstructionView->hide();
        selectInstructionView->hide();
        skipConditionView->hide();
        outputInstructionView->hide();
        coordinateInstructionView->hide();
        otherInstructionView->hide();
        otherInstructionView->otherInstruction2View->hide();
        palletInstructionView->hide();
        palletInstructionView->palletMotionInstructionView->hide();

        visionInstructionView->hide();

        moveMagInstructionView->hide();
        moveFreeInstructionView->hide();
        moveFreeInstructionView->moveFreeDPointView->hide();
        moveFreeInstructionView->moveFreeMoveTypeView->hide();
        moveFreeInstructionView->moveFreeVmarkSettingView->hide();

        modbusStartInstructionView->hide();
        modbusReadInstructionView->hide();
        modbusWriteInstructionView->hide();

        odometryInstructionView->hide();

        tcpStartInstructionView->hide();
        tcpReadInstructionView->hide();
        tcpWriteInstructionView->hide();

        musicInstructionView->hide();

        chargingInstructionView->hide();

        liftMechanismInstructionView->hide();
        loadMapInstructionView->hide();

        checkBatteryView->hide();
        waitCommandView->hide();

        robotMoveInstructionView->hide();
        rollerInstructionView->hide();

        axisMoveInstructionView->hide();

        //新指令20191130 ZHUHT
        weldStartInsView->hide();
        weldEndInsView->hide();
        weaveInsView->hide();
        weaveEndInsView->hide();
        trackWeldTASTInsView->hide();
        trackWeldEndInsView->hide();
        watchDIInsView->hide();
        lasercameraControlInsView->hide();
        lasercameraTrackInsView->hide();
        lasercameraFetchPointInsView->hide();
        bufferMoveView->hide();

    }
    else if(1 == instructionListFlag)
    {
        ui->InstructionListBtn->setStyleSheet(editInstructionBtnPicture1);
        ui->InstructionPropertyBtn->setStyleSheet(editInstructionBtnPicture2);

        ui->wdcommandmain->hide();
        ui->HideOrShow_AddCommand_Btn->hide();

        switch (editInstructionViewIndex)
        {
            case EM_EDIT_INSTRUCTION_MOTION:
            {
                motionInstructionView->show();
                motionInstructionDelegate->initialView();
                break;
            }
            case EM_EDIT_INSTRUCTION_IF:
            {
                ifInstructionView->show();
                ifInstructionDelegate->initialView();
                break;
            }
            case EM_EDIT_INSTRUCTION_LBLJMP:
            {
                labelJmpView->show();
                labelJmpDelegate->initialView();
                break;
            }
            case EM_EDIT_INSTRUCTION_WAIT:
            {
                waitInstructionView->show();
                waitInstructionDelegate->initialView();
                break;
            }
            case EM_EDIT_INSTRUCTION_FOR:
            {
                forInstructionView->show();
                forInstructionDelegate->initialView();
                break;
            }
            case EM_EDIT_INSTRUCTION_REGISTER:
            {
                registerInstructionView->show();
                registerInstructionDelegate->initialView();
                break;
            }
            case EM_EDIT_INSTRUCTION_SELECT:
            {
                selectInstructionView->show();
                selectInstructionDelegate->initialView();
                break;
            }
            case EM_EDIT_INSTRUCTION_SKIP:
            {
                skipConditionView->show();
                skipConditionDelegate->initialView();
                break;
            }
            case EM_EDIT_INSTRUCTION_OUTPUT:
            {
                outputInstructionView->show();
                outputInstructionDelegate->initialView();
                break;
            }
            case EM_EDIT_INSTRUCTION_COORDINATE:
            {
                coordinateInstructionView->show();
                coordinateInstructionDelegate->initialView();
                break;
            }
            case EM_EDIT_INSTRUCTION_OTHER:
            {
                otherInstructionView->show();
                otherInstructionDelegate->initialView();
                break;
            }
            case EM_EDIT_INSTRUCTION_PALLET:
            {
                palletInstructionView->show();
                palletInstructionDelegate->initialView();
                break;
            }
            case EM_EDIT_INSTRUCTION_PALLET_MOTION:
            {
                palletInstructionView->palletMotionInstructionView->show();
                palletInstructionDelegate->initialView();
                break;
            }
            case EM_EDIT_INSTRUCTION_VISION://2017.05.04 添加
            {
                visionInstructionView->show();
                break;
            }
            /************************************************************************
             * 修改者：         hualei
             * 修改时间:   (1) 2018-06-21
             *             (2) 2018-07-04
             *             (3) 2018-08-01
             *
             * 修改说明：　 1- 增加MOVE_MAG、MOVE_FREE 导航指令属性视窗索引显示
             *              2- 增加MODBUS_START、MODBUS_READ、MODBUS_WRITE 总线指令属性视窗索引显示
             *              3- 增加 TCP 以太网通信指令属性窗口显示索引
             *
             * ***********************************************************************/
            case EM_EDIT_INSTRUCTION_MOVE_MAG:      // 磁导航指令属性界面
            {
                moveMagInstructionView->show();
                moveMagInstructionDelegate->initView();
                break;
            }
            case EM_EDIT_INSTRUCTION_MOVE_FREE:      // 自由导航指令属性界面
            {
                moveFreeInstructionView->show();
                moveFreeInstructionDelegate->initView();
                break;
            }
            case EM_EDIT_INSTRUCTION_MODBUS_START:      // 总线开始指令属性界面
            {
                modbusStartInstructionView->show();
                modbusStartInstructionDelegate->initView();
                break;
            }
            case EM_EDIT_INSTRUCTION_MODBUS_READ:      // 总线读寄存器指令属性界面
            {
                modbusReadInstructionView->show();
                modbusReadInstructionDelegate->initView();
                break;
            }
            case EM_EDIT_INSTRUCTION_MODBUS_WRITE:      // 总线写寄存器指令属性界面
            {
                modbusWriteInstructionView->show();
                modbusWriteInstructionDelegate->initView();
                break;
            }
            case EM_EDIT_INSTRUCTION_SET_ODOM:          // 重置里程计指令属性界面
            {
                odometryInstructionView->show();
                odometryInstructionDelegate->initView();
                break;
            }
            case EM_EDIT_INSTRUCTION_TCP_START:          // tcp 以太网联通指令属性界面
            {
                tcpStartInstructionView->show();
                tcpStartInstructionDelegate->initialView();
                break;
            }
            case EM_EDIT_INSTRUCTION_TCP_READ:          // tcp 以太网接收指令属性界面
            {
                tcpReadInstructionView->show();
                tcpReadInstructionDelegate->initialView();
                break;
            }
            case EM_EDIT_INSTRUCTION_TCP_WRITE:          // tcp 以太网发送指令属性界面
            {
                tcpWriteInstructionView->show();
                tcpWriteInstructionDelegate->initialView();
                break;
            }
            case EM_EDIT_INSTRUCTION_MUSIC:             // MUSIC 音乐指令属性界面
            {   
                musicInstructionView->show();
                musicInstructionDelegate->initView();
                break;
            }
            case EM_EDIT_INSTRUCTION_CHARGING:             // CHARGING 充电指令属性界面
            {
                chargingInstructionView->show();
                chargingInstructionDelegate->initView();
                break;
            }
            case EM_EDIT_INSTRUCTION_LIFT:              // LIFT 升降机构指令属性界面
            {
                liftMechanismInstructionView->show();
                liftMechanismInstructionDelegate->initView();
                break;
            }
            case EM_EDIT_INSTRUCTION_LOAD_MAP:              // LOAD_MAP 加载地图指令属性界面
            {
                loadMapInstructionView->show();
                loadMapInstructionDelegate->initView();
                break;
            }
            case EM_EDIT_INSTRUCTION_CHECK_BATTERY:              // CHECK_BATTERY 加载地图指令属性界面
            {
                checkBatteryView->show();
                checkBatteryDelegate->initView();
                break;
            }
            case EM_EDIT_INSTRUCTION_WAIT_COMMAND:              // WAIT_COMMAND 加载地图指令属性界面
            {
                waitCommandView->show();
                waitCommandDelegate->initView();
                break;
            }
            case EM_EDIT_INSTRUCTION_ROBOT_MOVE:              // ROBOT_MOVE机械手控制指令属性界面
            {
                robotMoveInstructionView->show();
                robotMoveInstructionDelegate->initView();
                break;
            }
            case EM_EDIT_INSTRUCTION_ROLLER:                // ROLLER 滚筒控制指令属性界面
            {
                rollerInstructionView->show();
                rollerInstructionDelegate->initView();
                break;
            }
        case EM_EDIT_INSTRUCTION_AXIS_MOVE:
        {
            axisMoveInstructionView->show();
            axisMoveInstructionDelegate->initView();
            break;
        }
        case EM_EDIT_INSTRUCTION_WELD_START://拓展新指令增加代码20191122hualei
        {
            weldStartInsView->show();
            break;
        }
        case EM_EDIT_INSTRUCTION_WELD_END:
        {
            weldEndInsView->show();
            break;
        }
        case EM_EDIT_INSTRUCTION_WEAVE:
        {
            weaveInsView->show();
            break;
        }
        case EM_EDIT_INSTRUCTION_WEAVE_END:
        {
            weaveEndInsView->show();
            break;
        }
//新指令20191130 ZHUHT
        case EM_EDIT_INSTRUCTION_TRACKWELD_TAST:
        {
            trackWeldTASTInsView->show();
            break;
        }
        case EM_EDIT_INSTRUCTION_TRACKWELD_END:
        {
            trackWeldEndInsView->show();
            break;
        }
        case EM_EDIT_INSTRUCTION_WATCHDI:
        {
            watchDIInsView->show();
            break;
        }
        case EM_EDIT_INSTRUCTION_LASERCAMERA_CTRL:
        {
            lasercameraControlInsView->show();
            break;
        }
        case EM_EDIT_INSTRUCTION_LASERCAMERA_TRACK:
        {
            lasercameraTrackInsView->show();
            break;
        }
        case EM_EDIT_INSTRUCTION_LASERCAMERA_FETCHP:
        {
            lasercameraFetchPointInsView->show();
            break;
        }
        case EM_EDIT_INSTRUCTION_BUFFERMOVE:
        {
            bufferMoveView->show();
            break;
        }
            default:
                break;
        }
    }
}

void ProgramView::on_Command_tableWidget_doubleClicked(const QModelIndex &index)
{
        emit getCurrentLineInstruction(getCurrentLineIndex());

        emit openInstructionEditView();
}


void ProgramView::on_Command_tableWidget_clicked(const QModelIndex &index)
{
    currentLineIndex = index.row();
}

void ProgramView::on_menu_stackedWidget_destroyed()
{

}

void ProgramView::changeLanguage(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/programViewEnglishLan.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
    ui->retranslateUi(this);

    flowMenu->changeLanguage();
    instructionMenu_all->changeLanguage();
    instructionMenu_usualyUsed1->changeLanguage();
    instructionMenu_usualyUsed2->changeLanguage();
    ioMenu->changeLanguage();
    moveMenu->changeLanguage();
    otherMenu1->changeLanguage();
    palletMenu->changeLanguage();
    pointViewDialog->changeLanguage();
    registerMenu->changeLanguage();
    //stampMenu->changeLanguage();
    /************************************************************************
     * 修改者：     hualei
     * 修改时间:    2018-06-21
     * 修改说明：　增加MOVE_MAG、MOVE_FREE 导航指令属性视窗语言更改
     * ***********************************************************************/
    guidanceMenu->changeLanguage();
    modbusMenu->changeLanguage();
    tcpCommunicationMenu->changeLanguage();
    laserCameraMenu->changeLanguage();
}

QString &ProgramView::getCurrentSelectionInstruction()
{
    emit getCurrentLineInstruction(ui->Command_tableWidget->currentRow());
    currentSeletionInstruction = currentLineInstruction;
    qDebug() << "getCurrentSelectionInstruction ,current Selection Instruction :" << currentSeletionInstruction;
    return currentSeletionInstruction;
}

int ProgramView::readButtonConfigFunction(QString configPath, QMap<int, int> &usualButtonFunctionOut)
{
    qDebug() << "readButtonConfigFunction ==== 初始化配置文件：" << configPath;

    DomParser domparser;
    bool ok = domparser.openXml(configPath, QIODevice::ReadOnly);
    if( !ok )
    {
        qDebug() << "error domparser.openXml(configFileName, QIODevice::ReadOnly)：";
        return -1;
    }

    QDomNodeList devNodes = domparser.getRootDomElement().childNodes();

    usualButtonFunctionOut.clear();
    for(int i=0;i<devNodes.size();i++)
    {

        if(false==devNodes.at(i).toElement().hasAttribute("buttonId" ))
        {
            qDebug() << "error devNodes[i].toElement().hasAttribute buttonId ";
            return -10;
        }
        int buttonId = devNodes.at(i).toElement().attribute("buttonId" ).toUInt();
        if(false==devNodes.at(i).toElement().hasAttribute("commandId" ))
        {
            qDebug() << "error error devNodes[i].toElement().hasAttribute commandId";
            return -11;
        }
        int commandId = devNodes.at(i).toElement().attribute("commandId" ).toUInt();
        usualButtonFunctionOut.insert(buttonId,commandId);
    }

    domparser.closeXml();
    return 1;
}

void ProgramView::on_Command_tableWidget_itemClicked(QTableWidgetItem *item)
{
    // 获取选中指令内容(英文)
    emit getCurrentLineInstruction(item->row());
    currentSeletionInstruction = currentLineInstruction;
    qDebug() << "current Selection Instruction :" << currentSeletionInstruction;
}

void ProgramView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        //ui->设置所有控件的位置和大小。
        this->setGeometry(0,0,610,450);
        ui->Command_tableWidget->setGeometry(3,0,225,390);
        ui->HideOrShow_AddCommand_Btn->setGeometry(365,5,80,40);
        ui->Root_Mode_Btn->setGeometry(200,3,160,45);
        ui->Root_Mode_Btn->setParent(this);

        ui->menu_stackedWidget->setGeometry(235,0,215,390);
        ui->page_1->setGeometry(0,0,215,390);

        ui->ProgramOperWd->setGeometry(458,50,150,390);
        ui->ProgramOperWd->setParent(this);
        ui->MoveUpBtn->setGeometry(10,17,60,40);
        ui->MoveDownBtn->setGeometry(80,17,60,40);
        ui->DelBtn->setGeometry(10,62,60,40);
        ui->NoteBtn->setGeometry(80,62,60,40);
        ui->RecordPointBtn->setGeometry(10,107,60,40);
        ui->ShowPointBtn->setGeometry(80,107,60,40);
        ui->JToPointBtn->setGeometry(10,152,60,40);
        ui->LToPointBtn->setGeometry(80,152,60,40);
        ui->SaveBtn->setGeometry(10,197,60,40);
        ui->MoveToPointBtn->setGeometry(80,197,60,40);

        break;
    default:
        break;
    }
}
